package com.foreknow.demo8;

public class Student {
    private String name;
    private int id;
    private int score;

    public Student(String name, int id, int score) {
        this.name = name;
        this.id = id;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public Student[] getSort(Student[] s1){
        for(int j = 1;j<s1.length;j++){
            for(int i = 0;i<s1.length-j;i++){
                if(s1[i].getScore() < s1[i+1].getScore()){
                    Student temp = s1[i];
                    s1[i] = s1[i+1];
                    s1[i+1] = temp;
                }
            }
        }
        return s1;
    }
    public static void main(String[] args) {
        Student st1 = new Student("张三",101,90);
        Student st2 = new Student("李四",102,80);
        Student st3 = new Student("王五",103,100);
        Student[] s = {st1,st2,st3};
        Student[] ss = st2.getSort(s);
        for(int i = 0;i<ss.length;i++){
            System.out.println(ss[i].getName()+"同学的学号为"+ss[i].getId()+",其成绩为"+ss[i].getScore()+",名次为"+(i+1));
        }
    }
}
